<template>
  <!-- <div class="content-box">
  <common-header :title="title" ></common-header>-->
  <div class="page-content">
    <van-field
      v-model="idCard"
      type="text"
      clearable
      label="身份证"
      placeholder="请输入身份证"
      required
      error-message-align="right"
      :error-message="idCardMessage"
    />
    <van-field
      v-model="name"
      type="text"
      label="姓名"
      placeholder="请输入姓名"
      clearable
      required
      error-message-align="right"
      :error-message="nameMessage"
    />
    <!-- <div class="payDetails">
        <div class="title">身份证照片</div>
        <div class="text">
          <van-uploader v-model="fileList" multiple :max-count="2" :after-read="afterRead" />
        </div>
    </div>-->

    <div class="btnPay" @click="submit()">立即认证</div>
    <commonFooter></commonFooter>
  </div>
  <!-- </div> -->
</template>
<script>
import { commonFooter } from "common";
import { idcardReg } from "@/utils/regRex";
import { realauth } from "@/api/user";
import { createNamespacedHelpers } from "vuex";
let { mapGetters, mapState, mapActions } = createNamespacedHelpers("user");
export default {
  name: "recharge",
  components: {
    commonFooter
  },

  methods: {
    ...mapActions(["GetInfo"]),
    submit() {
      let _this = this;
      this.nameMessage = "";
      this.idCardMessage = "";
      if (!this.name) {
        this.nameMessage = "请输入姓名";
      }
      if (!this.idCard) {
        this.idCardMessage = "请输入身份证";
      } else if (!idcardReg.test(this.idCard)) {
        this.idCardMessage = "请输入正确的身份证";
      } else if (this.name) {
        realauth({
          card_id: this.idCard,
          name: this.name
        }).then(res => {
          this.$toast({
            message: res.msg,
            duration: 500,
            onClose: function() {
              _this.GetInfo().then(res => {
                if (res.code == 200) {
                  if (_this.$route.query.redirect) {
                    _this.$router.replace({
                      path: _this.$route.query.redirect
                    });
                  } else {
                    _this.$router.push("/user");
                  }
                } else {
                  return;
                }
              });
            }
          });
        });
      }
    }
  },
  data() {
    return {
      title: "身份认证",
      idCard: "",
      idCardMessage: "",
      name: "",
      nameMessage: ""
    };
  }
};
</script>
<style lang="less" scoped>
@import "~styles/variable.less";
/deep/ .van-radio {
  float: left;
  position: relative;
  top: 0.2rem;
  margin-right: 0.5rem;
  span {
    color: #666 !important;
    font-size: 0.35rem;
  }
}
</style>